#include <stdio.h>
#include "netforward.h"
#include <assert.h>
#include "thrqueue.h"
#include <unistd.h>
#include "uv_thread.h"

thrqueue_t *g_q;

void testq()
{
    int data = 0;
    void *ret = NULL;

    char *temp = NULL;

    sleep(2);
    asprintf(&temp, "%d", data++);
    ret = thrqueue_enqueue(g_q, temp);
    printf("enquene %s\n", temp);
    asprintf(&temp, "%d", data++);
    ret = thrqueue_enqueue(g_q, temp);
    printf("enquene %s\n", temp);
    asprintf(&temp, "%d", data++);
    ret = thrqueue_enqueue(g_q, temp);
    printf("enquene %s\n", temp);
    asprintf(&temp, "%d", data++);
    ret = thrqueue_enqueue(g_q, temp);
    printf("enquene %s\n", temp);
}

void* testq2(void *parm)
{
    printf("%s E\n", __func__);
    char *data = (char *)thrqueue_dequeue(g_q);
    printf("%s\n", data);
    sleep(1);
    data = (char *)thrqueue_dequeue(g_q);
    printf("%s\n", data);
    data = (char *)thrqueue_dequeue(g_q);
    printf("%s\n", data);
    data = (char *)thrqueue_dequeue(g_q);
    printf("%s\n", data);
    data = (char *)thrqueue_dequeue(g_q);
    printf("%s\n", data);
    data = (char *)thrqueue_dequeue(g_q);
    printf("%s\n", data);
    return NULL;
}

int main(int ac, char**av) 
{
    printf("HelloWorld\n");

    g_q = thrqueue_new(3);
    uv_thread_t tid;
    uv_thread_create(&tid, (uv_thread_cb)testq2, NULL);

    testq();


    while(1){
        sleep(100);
    }

    return 0;
}
